Change in openvpn[master]: Trigger renegotiation of data key if getting close to the AEAD usage ...
A message that is not in the archive (sent off-list or not yet received): gerrit.1731290343000.I057f007577f10c6ac917ee4620ee3d2559187dc7@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to review the following change.
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoiding needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effects that connection with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Change-Id: Idccc93f303d29869ef4ed10b6bb56f37efedf623
Testing instructions: The easiest way to test if this patch works as intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
Change-Id: I0d2c763fd1dcdacdd8993731fc4979e258d1da4e
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 159 insertions(+), 5 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/1
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +43 -0
67 lines not on this page · raw message
src/openvpn/crypto.h +37 -0
@@ -166,6 +166,9 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext encrypted using this cipher +* in number of 128 bit blocks (only used for AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +599,24 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of block + packets. Return -1 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +int64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +624,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const int64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +44 -3
74 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** This limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +int64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +24 -2
@@ -448,6 +448,27 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,8 +479,9 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) - }; +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) + };#if defined(ENABLE_CRYPTO_OPENSSL )OpenSSL_add_all_algorithms ();
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 1:
(3 comments)
Patchset:
PS1:
minor typo and a question about <math.h>
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/b2b1e089_c3b3a093 :
PS1, Line 615: * Since cipher_ctx_block_size() is reliable and will return 1 in many "is not reliable"?
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/74449d2c_0a6e8ccd :
PS1, Line 40: #include <math.h>
where's that coming from? I see not math-typical functions being called (round() etc) in the new code?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 11 Nov 2024 17:59:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 3:
(2 comments)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/7d70e94e_b31d44b6 :
PS1, Line 615: * Since cipher_ctx_block_size() is reliable and will return 1 in many
Quoted 1 line
"is not reliable"?
Done
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/1fd81608_087915dd :
PS1, Line 40: #include <math.h>
Quoted 1 line
where's that coming from? I see not math-typical functions being called (
round()etc) in the new co […]
Earlier version used math to calculate those limits but then I got into all the linking problem with -lm and then decided that I rather use in based math instead ....
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 14 Nov 2024 13:47:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#4).
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoiding needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effects that connection with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Change-Id: Idccc93f303d29869ef4ed10b6bb56f37efedf623
Testing instructions: The easiest way to test if this patch works as intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
Change-Id: I0d2c763fd1dcdacdd8993731fc4979e258d1da4e
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 156 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/4
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +37 -0
@@ -166,6 +166,9 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext encrypted using this cipher +* in number of 128 bit blocks (only used for AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +599,24 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of block + packets. Return -1 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +int64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +624,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const int64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** This limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +int64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +23 -1
@@ -448,6 +448,27 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +479,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 6: Code-Review-1
(8 comments)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/cd492ae9_fd17bd7c :
PS6, Line 603: * number of number of block + packets. Return -1 if ciphername is not an AEAD "blocks"
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/884aa131_043fac76 :
PS6, Line 353: * q + s <= (p^36 - 1)2^36
http://gerrit.openvpn.net/c/openvpn/+/796/comment/5487e9b6_1af10abb :
PS6, Line 502: /* update number of plaintext blocks decrypted. Use the x + (n-1)/n trick
Should be (x + (n-1))/n. The code is correct, but comment is wrong.
http://gerrit.openvpn.net/c/openvpn/+/796/comment/38ba5a32_7a3341ec :
PS6, Line 503: * to round up the result to the number of blocked used. */
"blocks"
http://gerrit.openvpn.net/c/openvpn/+/796/comment/4cbb5beb_e82ad0e6 :
PS6, Line 505: opt->key_ctx_bi.decrypt.plaintext_blocks += (outlen + (blocksize - 1))/blocksize;
So we increase this number before we have done all checks on the packet. Doesn't that open us up to potential attacks that force renegotiation by replaying packets?
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/dc63e5a8_82d0b335 :
PS6, Line 144: /* set limit to 7/8 of the limit so the renogiation has can succeeds before
"renegotiation can succeed" ?
File src/openvpn/ssl_common.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/728ac18b_aa309cd4 :
PS6, Line 336: /** This limit for AEAD cipher, this is the sum of packets + blocks
"This" -> "The"? Or maybe just remove it?
File tests/unit_tests/openvpn/test_crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/fd854db2_f454d881 :
PS6, Line 463: int64_t L = 101;
Please mention or use AEAD_LIMIT_BLOCKSIZE
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 09:47:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 6: Code-Review-2
(6 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/6f5c1440_6ba1cc3d :
PS6, Line 17: For a VPN OpenVPN, the same calculation would either require using a "VPN like OpenVPN"? Or just "For OpenVPN"?
http://gerrit.openvpn.net/c/openvpn/+/796/comment/e9855faf_bebc8208 :
PS6, Line 24: To avoid this dynamic calculation and also avoiding needing to know the "avoid"
http://gerrit.openvpn.net/c/openvpn/+/796/comment/56e7feb1_cedb0de9 :
PS6, Line 29: This also has the side effects that connection with a lot of small packets "connections"
http://gerrit.openvpn.net/c/openvpn/+/796/comment/374d394d_c29d4c00 :
PS6, Line 30: (like TCP ACKs) mixed with large packets will be able to keep using the same "same key"?
http://gerrit.openvpn.net/c/openvpn/+/796/comment/4815cde9_b38338fa :
PS6, Line 34: of the
"of the actual limit"?
http://gerrit.openvpn.net/c/openvpn/+/796/comment/efd85c78_167db128 :
PS6, Line 50: Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7 Why does this have three Change-Ids?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 10:03:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 6:
(6 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/933872f5_aebd1b85 :
PS6, Line 17: For a VPN OpenVPN, the same calculation would either require using a
Quoted 1 line
"VPN like OpenVPN"? Or just "For OpenVPN"?
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/ca599a2c_8f021338 :
PS6, Line 24: To avoid this dynamic calculation and also avoiding needing to know the
Quoted 1 line
"avoid"
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/dbf4f6ff_4d8eca15 :
PS6, Line 29: This also has the side effects that connection with a lot of small packets
Quoted 1 line
"connections"
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/2fede922_5b7df247 :
PS6, Line 30: (like TCP ACKs) mixed with large packets will be able to keep using the same
Quoted 1 line
"same key"?
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/578c0f8b_24b20229 :
PS6, Line 34: of the
Quoted 1 line
"of the actual limit"?
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/75c4d609_2a233adb :
PS6, Line 50: Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Quoted 1 line
Why does this have three Change-Ids?
That is a good question, some that post commit script did some nonsense, I will try to figure out which is the right one and remove the other two.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 18:40:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#7).
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 159 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/7
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +43 -0
61 lines not on this page · raw message
src/openvpn/crypto.h +37 -0
@@ -166,6 +166,9 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext encrypted using this cipher +* in number of 128 bit blocks (only used for AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +599,24 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return -1 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +int64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +624,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const int64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +int64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 7:
(9 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/afd7f3b3_34658dc4 :
PS6, Line 50: Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Quoted 1 line
That is a good question, some that post commit script did some nonsense, I will try to figure out wh […]
Done
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/424ddba6_d7884def :
PS6, Line 603: * number of number of block + packets. Return -1 if ciphername is not an AEAD
Quoted 1 line
"blocks"
Done
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/734aa10c_22eb3343 :
PS6, Line 353: * q + s <= (p^36 - 1)
Quoted 1 line
2^36
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/827f411c_2ae94fdb :
PS6, Line 502: /* update number of plaintext blocks decrypted. Use the x + (n-1)/n trick
Quoted 1 line
Should be
(x + (n-1))/n. The code is correct, but comment is wrong.
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/eaad6627_493699fa :
PS6, Line 503: * to round up the result to the number of blocked used. */
Quoted 1 line
"blocks"
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/c3a09ead_b2f38a1c :
PS6, Line 505: opt->key_ctx_bi.decrypt.plaintext_blocks += (outlen + (blocksize - 1))/blocksize;
Quoted 1 line
So we increase this number before we have done all checks on the packet. […]
thanks good catch.
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/e2fcb49b_de363156 :
PS6, Line 144: /* set limit to 7/8 of the limit so the renogiation has can succeeds before
Quoted 1 line
"renegotiation can succeed" ?
Acknowledged
File src/openvpn/ssl_common.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/c98780b7_0c3c5759 :
PS6, Line 336: /** This limit for AEAD cipher, this is the sum of packets + blocks
Quoted 1 line
"This" -> "The"? Or maybe just remove it?
Done
File tests/unit_tests/openvpn/test_crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/918d7aea_2d1e7962 :
PS6, Line 463: int64_t L = 101;
Quoted 1 line
Please mention or use
AEAD_LIMIT_BLOCKSIZE
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 19:02:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 7: Code-Review-1
(3 comments)
Patchset:
PS7:
The limit matches the one in the RFC for p = 2^57.
I have some nitpicks about comments.
And one question: The RFC also specifies a limit for message integrity. If v is the number of failed decryptions for the current key and L is the maximum number of blocks per message, we must make sure that v <= min(2^64, (p * 2^127) / (L + 1)). Are we going to check that too?
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/cb71ff95_59bc6586 :
PS7, Line 169: /** Counter for the number of plaintext encrypted using this cipher
: * in number of 128 bit blocks (only used for AEAD ciphers) */
This looks a bit garbled. Maybe "Counter for the number of 128-bit plaintext blocks encrypted with the current key"?
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/ab160cf8_a5e88f45 :
PS7, Line 347: q <= (p^(1/2) * 2^(129/2) - 1) / (L + 1)
We're not doing anything with this inequality. This one is for the case where we don't count the individual blocks but just have an upper bound of L on the number of blocks per message.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 29 Nov 2024 14:05:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 7:
(2 comments)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/425b7b90_d202b3d9 :
PS7, Line 169: /** Counter for the number of plaintext encrypted using this cipher
: * in number of 128 bit blocks (only used for AEAD ciphers) */
Quoted 1 line
This looks a bit garbled. […]
Done
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/3b5c18b9_d1b170ca :
PS7, Line 347: q <= (p^(1/2) * 2^(129/2) - 1) / (L + 1)
Quoted 1 line
We're not doing anything with this inequality. […]
Yes, I will remove that one. The earlier version used L but it is easier do the block counting that actually figuring out L.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 30 Nov 2024 12:46:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 7:
(1 comment)
Patchset:
PS7:
Quoted 1 line
The limit matches the one in the RFC for p = 2^57. […]
I will add that as seperate commit later in the patch (to be sent, it is not there yet). We will probably aim for the 2^36 limits that also TLS uses.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 30 Nov 2024 12:48:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
Hello MaxF, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#8).
The following approvals got outdated and were removed:
Code-Review-1 by MaxF
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 159 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/8
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +38 -0
@@ -166,6 +166,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +600,24 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return -1 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +int64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +625,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const int64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +int64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 9: Code-Review-1
(1 comment)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/a302425a_a5242f5e :
PS9, Line 604: Return -1
The code is returning 0.
Given that, you could also make the function return an unint which I would like because an int-uint comparison is making me feel a bit paranoid. (Though even then highest_pid is still an int.)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 9
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 02 Dec 2024 14:26:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 9:
(1 comment)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/42d71047_818ce5cc :
PS9, Line 604: Return -1
Quoted 1 line
The code is returning 0. […]
I fixed the description and made it an unsigned int.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 9
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Tue, 03 Dec 2024 11:06:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
Hello MaxF, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#10).
The following approvals got outdated and were removed:
Code-Review-1 by MaxF
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 160 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/10
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -166,6 +166,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +600,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +626,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const int64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +int64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 10: Code-Review-1
(4 comments)
Patchset:
PS10:
I've pointed out a few more places where you could use uint. Let me know if this is excessive nitpicking.
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/56ca9914_0cae7c14 :
PS10, Line 355: int64_t
This could be uint
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/ca8aab0e_b7f91c98 :
PS10, Line 134: static int64_t
: tls_get_limit_aead(const char *ciphername)
: {
: int64_t limit = cipher_get_aead_limits(ciphername);
:
: if (limit == 0)
: {
: return 0;
: }
:
: /* set limit to 7/8 of the limit so the renogiation can succeed before
: * we go over the limit */
: limit = limit * 7/8;
:
: msg(D_SHOW_KEYS, "Note: AEAD cipher %s will be limited to a sum of %"
: PRIi64 " for block and packets before renegotiation",
: ciphername, limit);
: return limit;
: }This function could return uint
File src/openvpn/ssl_common.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/166427ee_9749af9d :
PS10, Line 338: int64_t aead_usage_limit;
This could be uint
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 03 Dec 2024 13:48:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld, plaisthos.
Hello MaxF, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#11).
The following approvals got outdated and were removed:
Code-Review-1 by MaxF
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 160 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/11
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -166,6 +166,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +600,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +626,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 11
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: MaxF, cron2, flichtenheld, plaisthos.
Hello MaxF, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#12).
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 160 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/12
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -166,6 +166,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +600,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +626,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +43 -2
71 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: MaxF, cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 10:
(2 comments)
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/f04661f0_7a09925d :
PS10, Line 355: int64_t
Quoted 1 line
This could be uint
Acknowledged
File src/openvpn/ssl_common.h:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/ceef0504_77360f1e :
PS10, Line 338: int64_t aead_usage_limit;
Quoted 1 line
This could be uint
Acknowledged
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Tue, 03 Dec 2024 14:08:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld, plaisthos.
syzzer has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 12: Code-Review-1
(5 comments)
Patchset:
PS12:
Looks good in general. Math checks out. Some minor nits and one fundamental remark to consider.
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/2fd3c45a_2a4cdbb4 :
PS12, Line 144: /* set limit to 7/8 of the limit so the renogiation can succeed before
renegotiation
http://gerrit.openvpn.net/c/openvpn/+/796/comment/a6fc21b4_8bd28a4d :
PS12, Line 146: limit = limit * 7/8;
Consider adding overflow checks. I know, unlikely, and doesn´t result in an unsafe situation, but if cipher_get_aead_limits at some point could return values close to 2**64, this calculation could result in very low limit values.
http://gerrit.openvpn.net/c/openvpn/+/796/comment/7971040c_bac1d94b :
PS12, Line 149: PRIi64 " for block and packets before renegotiation",
This suggests a hard limit, but it's a soft limit we can (and typically will) exceed. Without the 64-bit pid, we had a hard limit at 2**32-1. To be able to claim we never exceed the real limit (the "8/8" value), we should consider adding a hard limit enforcement.
http://gerrit.openvpn.net/c/openvpn/+/796/comment/502879b2_3c1a0f24 :
PS12, Line 3027: || aead_usage_limit_reached(usage_limit, &key_ctx_bi->decrypt,
This is a safety precaution? The sending party is ultimately responsible for not exceeding the limit of course. (But I admit, in practice this would likely prevent buggy peers from exceeding the limit.)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Dec 2024 21:15:40 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld, plaisthos, syzzer.
Hello MaxF, flichtenheld, syzzer,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
to look at the new patch set (#13).
The following approvals got outdated and were removed:
Code-Review-1 by syzzer
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 169 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/13
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -166,6 +166,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -596,6 +600,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -603,4 +626,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +52 -2
80 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: syzzer <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: MaxF, cron2, flichtenheld, syzzer.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 13:
(5 comments)
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/c237d8e4_41a211f7 :
PS10, Line 134: static int64_t
: tls_get_limit_aead(const char *ciphername)
: {
: int64_t limit = cipher_get_aead_limits(ciphername);
:
: if (limit == 0)
: {
: return 0;
: }
:
: /* set limit to 7/8 of the limit so the renogiation can succeed before
: * we go over the limit */
: limit = limit * 7/8;
:
: msg(D_SHOW_KEYS, "Note: AEAD cipher %s will be limited to a sum of %"
: PRIi64 " for block and packets before renegotiation",
: ciphername, limit);
: return limit;
: }Quoted 1 line
This function could return uint
Done
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/9c45c755_8086e09c :
PS12, Line 144: /* set limit to 7/8 of the limit so the renogiation can succeed before
Quoted 1 line
renegotiation
Done
http://gerrit.openvpn.net/c/openvpn/+/796/comment/ee3d97c9_67c4d1c6 :
PS12, Line 146: limit = limit * 7/8;
Quoted 1 line
Consider adding overflow checks. […]
I changed the order to /8 * 7 which does not have the overflow problem and I think if we now off by a few packets because of the lower precision that is not doing much in the grand scheme.
http://gerrit.openvpn.net/c/openvpn/+/796/comment/2ddba798_2401cb2d :
PS12, Line 149: PRIi64 " for block and packets before renegotiation",
Quoted 1 line
This suggests a hard limit, but it's a soft limit we can (and typically will) exceed. […]
The hard limit of 2**32-1 is still there. The higher pid limit only comes with the epoch patches and those actually have this as as a hard limit.
I think implementing a hard limit for this feature is not so important, so I changed the message to indicate that there will be a renegotiation.
http://gerrit.openvpn.net/c/openvpn/+/796/comment/55c0c5e2_32a406f5 :
PS12, Line 3027: || aead_usage_limit_reached(usage_limit, &key_ctx_bi->decrypt,
Quoted 1 line
This is a safety precaution? The sending party is ultimately responsible for not exceeding the limit […]
My thinking was that this code will most certainly only be in use when only one side is aware of the limitation. Since if both sides are aware, then both sides will probably also switch to use epoch data channel instead, which only the sender checks.
I will add a comment to indicate this as well.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: syzzer <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Thu, 12 Dec 2024 15:49:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: syzzer <[email protected]...>
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, syzzer.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 13: -Code-Review
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: syzzer <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Thu, 12 Dec 2024 17:03:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, plaisthos.
syzzer has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 13: Code-Review+1
(2 comments)
Patchset:
PS13:
Looks good conceptually. I don't have a dev/test setup available to actually do a full review, so sticking to +1.
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/796/comment/5601c42a_7ba38f22 :
PS12, Line 149: PRIi64 " for block and packets before renegotiation",
Quoted 1 line
The hard limit of 2**32-1 is still there. […]
Ahh, I didn't realize the hard limit arrived with the epoch patches. That's perfect.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Thu, 12 Dec 2024 20:02:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: syzzer <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Patch Set 14: Code-Review+2
(1 comment)
Patchset:
PS14:
This has been extensively reviewed by people who understand math and crypto. I have stared at the rest of the code, and it seems to make sense. Will do a "reduce limits, see what happens" test before final merge.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 14
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 21 Dec 2024 15:36:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v14 1/1 Trigger renegotiation of data key if getting close to the AEAD usage limit
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/796
This mail reflects revision 14 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -177,6 +177,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -607,6 +611,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -614,4 +637,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +52 -2
80 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
[Openvpn-devel] [PATCH applied] Re: Trigger renegotiation of data key if getting close to the AEAD usage limit
So, I tested this as instructed, setting a ridiculously low limit (10000), and "it does rekey often". There is one interesting aspect to it
2024-12-21 23:04:19 TLS: soft reset sec=91/3600 bytes=1043562/-1 pkts=6886/0 aead_limit_send=50100/8750 aead_limit_recv=6886/8750
.. with this low limit, we can exceed the limit by quite some marging
- which is due to "tls_process()" only being called every 15-16 seconds when in steady state (this is what checks should_trigger_renegotiation()), so "what happens in these 15 seconds" can go over the limit. Which is not a problem for the normal limit (~68719476736 *7/8, so roughly 8589934592 AEAD blocks in 15 seconds - we're fast, but not that fast).
Besides this, the code does nothing unexpected - it passes all client/server side tests, and changes nothing in process behaviour. So ACK from me, on top of the "crypto looks good" +1 from MaxF and Steffan.
Your patch has been applied to the master branch.
commit fb691d2dcc63a29dafdf11ca33837c758e2b13b7
Author: Arne Schwabe Date: Sat Dec 21 16:37:30 2024 +0100
Trigger renegotiation of data key if getting close to the AEAD usage limit
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30144.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#15) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
The following approvals got outdated and were removed:
Code-Review+1 by syzzer, Code-Review+2 by cron2
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30144.html
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 169 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/796/15
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -177,6 +177,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -607,6 +611,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -614,4 +637,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +52 -2
80 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 15
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/796?usp=email )
Change subject: Trigger renegotiation of data key if getting close to the AEAD usage limit
......................................................................
Trigger renegotiation of data key if getting close to the AEAD usage limit
This implements the limitation of AEAD key usage[1] with a confidentiality margin of 2^-57, the same as TLS 1.3. In this implementation, unlike TLS 1.3 that counts the number of records, we count the actual number of packets and plaintext blocks. TLS 1.3 can reasonable assume that for large data transfers, full records are used and therefore the maximum record size of 2**14 (2*10 blocks) is used to calculate the number of records before a new key needs to be used.
For a VPN like OpenVPN, the same calculation would either require using a pessimistic assumption of using a MTU size of 65k which limits us to 2^24 packets, which equals only 24 GB with more common MTU/MSS of 1400 or requiring a dynamic calculation which includes the actual MTU that we allow to send. For 1500 the calculation yields 2*29.4 which is a quite significant higher number of packets (923 GB at 1400 MSS/MTU).
To avoid this dynamic calculation and also avoid needing to know the MSS/MTU size in the crypto layer, this implementation foregoes the simplification of counting just packets but will count blocks and packets instead and determines the limit from that.
This also has the side effect that connections with a lot of small packets (like TCP ACKs) mixed with large packets will be able to keep using the same key much longer until requiring a renegotiation.
This patch will set the limit where to trigger the renegotiation at 7/8 of the recommended maximum value.
[1] https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html
Testing instructions:
The easiest way to test if this patch works as
intended is to manually change the return value of cipher_get_aead_limits to some silly low value like 2048. After a bit of VPN traffic, a soft reset should occur that indicates being over the
TLS: soft reset sec=41/3600 bytes=59720/-1 pkts=78/0 aead_limit_send=1883/1792 aead_limit_recv=1937/1792
Here the send limit is over the limit (1792 = 2048 * 8/7).
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30144.html
---
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 169 insertions(+), 3 deletions(-)
Changes.rst +8 -0
@@ -22,6 +22,14 @@ For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). +Enforcement of AES-GCM usage limit + OpenVPN will now enforce the usage limits on AES-GCM with the same + confidentiality margin as TLS 1.3 does. This mean that renegotiation will + be triggered after roughly 2^28 to 2^31 packets depending of the packet + size. More details about usage limit of AES-GCM can be found here: + + https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +42 -0
60 lines not on this page · raw message
src/openvpn/crypto.h +39 -0
@@ -177,6 +177,10 @@uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH ];/**< The implicit part of the IV */ size_t implicit_iv_len;/**< The length of implicit_iv */ +/** Counter for the number of plaintext block encrypted using this cipher +* with the current key in number of 128 bit blocks (only used for +* AEAD ciphers) */ +uint64_t plaintext_blocks; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -607,6 +611,25 @@ }/** +* Check if the cipher is an AEAD cipher and needs to be limited to a certain +* number of number of blocks + packets. Return 0 if ciphername is not an AEAD +* cipher or no limit (e.g. Chacha20-Poly1305) is needed. (Or the limit is +* larger than 2^64) +* +* For reference see the OpenVPN RFC draft and +* https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html +*/ +uint64_t +cipher_get_aead_limits (const char *ciphername); + +/** +* Blocksize used for the AEAD limit caluclation +* +* Since cipher_ctx_block_size() is not reliable and will return 1 in many +* cases use a hardcoded blocksize instead */ +#define AEAD_LIMIT_BLOCKSIZE 16 + +/** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 * that OpenVPN uses when TLS Keying Material Export is not available. *
@@ -614,4 +637,20 @@*/ bool check_tls_prf_working (void ); +/** +* Checks if the usage limit for an AEAD cipher is reached +* +* This method abstracts the calculation to make the calling function easier +* to read. +*/ +static inline bool +aead_usage_limit_reached (const uint64_t limit,const struct key_ctx *key_ctx, +int64_t higest_pid) +{ +/* This is the q + s <= p^(1/2) * 2^(129/2) - 1 calculation where +* q is the number of protected messages (highest_pid) +* s Total plaintext length in all messages (in blocks) */ +return (limit >0 && key_ctx->plaintext_blocks + (uint64_t ) higest_pid > limit); +} +#endif /* CRYPTO_H */
src/openvpn/ssl.c +52 -2
80 lines not on this page · raw message
src/openvpn/ssl_common.h +3 -0
@@ -333,6 +333,9 @@interval_t packet_timeout;int64_t renegotiate_bytes;int64_t renegotiate_packets; +/** limit for AEAD cipher, this is the sum of packets + blocks +* that are allowed to be used */ +uint64_t aead_usage_limit;interval_t renegotiate_seconds;/* cert verification parms */
tests/unit_tests/openvpn/test_crypto.c +25 -1
@@ -448,6 +448,29 @@gc_free (&gc); } +void +crypto_test_aead_limits (void **state) +{ +/* if ChaCha20-Poly1305 is not supported by the crypto library or in the +* current mode (FIPS), this will still return -1 */ +assert_int_equal (cipher_get_aead_limits ("CHACHA20-POLY1305" ),0 ); + +int64_t aeslimit =cipher_get_aead_limits ("AES-128-GCM" ); + +assert_int_equal (aeslimit, (1ull <<36 ) -1 ); + +/* Check if this matches our exception for 1600 size packets assuming +* AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks +* + 1 for the packet */ +int64_t L =101 ; +/* 2 ^ 29.34, using the result here to avoid linking to libm */ +assert_int_equal (aeslimit /L ,680390858 ); + +/* and for 9000, 2^26.86 */ +L =563 ; +assert_int_equal (aeslimit /L ,122059461 ); +} +int main (void ) {
@@ -458,7 +481,8 @@cmocka_unit_test (crypto_test_tls_prf),cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(crypto_test_aead_limits) };#if defined(ENABLE_CRYPTO_OPENSSL )
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/796?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I057f007577f10c6ac917ee4620ee3d2559187dc7
Gerrit-Change-Number: 796
Gerrit-PatchSet: 15
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: syzzer <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged